const mysql = require('mysql2/promise');

async function addSpecialWords() {
    const config = {
        host: 'localhost',
        user: 'root',
        password: 'Lycc.2025',
        database: 'fun_english_db',
        charset: 'utf8mb4'
    };

    let connection;

    try {
        console.log('连接数据库...');
        connection = await mysql.createConnection(config);
        
        // 5个特殊格式的单词
        const specialWords = [
            { word: 'ping-pong', phonetic: '/ˈpɪŋ pɒŋ/', chinese: '乒乓球', grade: '五上', unit: 'Unit 4' },
            { word: 'RSVP', phonetic: '//', chinese: '（尤用于请柬）请赐复', grade: '五下', unit: 'Unit 3' },
            { word: 'doing morning exercises', phonetic: '//', chinese: '做早操', grade: '五下', unit: 'Unit 6' },
            { word: 'BDS', phonetic: '//', chinese: '北斗卫星导航系统', grade: '六上', unit: 'Unit 1' },
            { word: 'pay attention to', phonetic: '//', chinese: '注意', grade: '六上', unit: 'Unit 2' }
        ];

        console.log('添加5个特殊格式的单词...\n');
        
        for (const word of specialWords) {
            await connection.execute(
                'INSERT IGNORE INTO vocabulary (word, phonetic, chinese, grade, unit) VALUES (?, ?, ?, ?, ?)',
                [word.word, word.phonetic, word.chinese, word.grade, word.unit]
            );
            console.log(`  ✓ ${word.word}`);
        }

        // 检查最终总数
        const [result] = await connection.query('SELECT COUNT(*) as total FROM vocabulary');
        const total = result[0].total;

        console.log('\n=================================');
        console.log(`✅ 当前单词总数: ${total} 个`);
        
        if (total === 848) {
            console.log('🎉 完美！正好848个单词！');
        } else {
            console.log(`⚠️  差异: ${848 - total} 个`);
        }
        console.log('=================================\n');

    } catch (error) {
        console.error('错误:', error.message);
    } finally {
        if (connection) {
            await connection.end();
        }
    }
}

addSpecialWords();

